import java.util.*;
public abstract class Scheduler{
	boolean running = true;
	int time = 0;
	int context_switch_count = 0;
	int context_switch_time = 0;
	double waittotal = 0;
	double turntotal = 0;
	ArrayList<Integer> wait_times = new ArrayList<Integer>();
	ArrayList<Integer> turnaround_times = new ArrayList<Integer>();
	ArrayList<Process> queue = new ArrayList<Process>();
	ArrayList<Process> processes = new ArrayList<Process>();
	abstract void run();
	public void add_process(ArrayList<Process> p){
		processes.addAll(p);
		Collections.sort(processes, new Arrival_Comparison());
	}
	public abstract void check_new();
	public abstract void context_switch();
	public void print_stats(){
		double waitmin = 10000000, waitmax = 0;
		double turnmin = 10000000, turnmax = 0;
		for(int i = 0; i < wait_times.size(); i++){
			if(wait_times.get(i) < waitmin)
				waitmin = wait_times.get(i);
			if(wait_times.get(i) > waitmax)
				waitmax = wait_times.get(i);
			if(turnaround_times.get(i) < turnmin)
				turnmin = turnaround_times.get(i);
			if(turnaround_times.get(i) > turnmax)
				turnmax = turnaround_times.get(i);
			waittotal += wait_times.get(i);
			turntotal += turnaround_times.get(i);
		}
		waittotal = waittotal/wait_times.size();
		turntotal = turntotal/wait_times.size();	
		System.out.println("Wait Times:");
        System.out.print("\tMinimum: " + waitmin + "ms");
        System.out.print("\tMaximum: " + waitmax + "ms");
        System.out.print("\tAverage: " + waittotal + "ms\n");
        System.out.println("Turnaround Times:");
        System.out.print("\tMinimum: " + turnmin + "ms");
        System.out.print("\tMaximum: " + turnmax + "ms");
        System.out.print("\tAverage: " + turntotal + "ms\n");
        System.out.println("Context Switches: " + context_switch_count);
        System.out.println("Total Time taken by Context Switches: " + context_switch_time + "ms");
	}
}